package wavenotes.model.wave;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.wave.api.Wavelet;


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class WaveState
{

	// TODO this needs to use the id for the primary key
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	

	@Persistent
	private String waveId;
	
	@Persistent
	private String listOfPresentations;	

	@Persistent
	private String listOfParticipants;	

	@Persistent
	private String presentationState;	

	@Persistent
	private String slideIndex;	

	@Persistent
	private String pollCount;

	@Persistent
	private String refreshPresentations;

	@Persistent
	private String presentationKey;

	@Persistent
	private String numberOfSlides;
	
	@Persistent
	private String presentationName;
	
	public String getWaveId()
	{
		return waveId;
	}
	
	public void setWaveId(String waveId)
	{
		this.waveId = waveId;
	}
	
	public String getRefreshPresentations()
	{
		return refreshPresentations;
	}
	
	public void setRefreshPresentations(String refreshPresentations)
	{
		this.refreshPresentations = refreshPresentations;
	}
	
	public static WaveState getWaveState(Wavelet wavelet, PersistenceManager pm)
	{
		Query jdoQuery = pm.newQuery(WaveState.class, "waveId == '" + wavelet.getWaveId() + "'");
		List<WaveState> waveStates = (List<WaveState>) jdoQuery.execute();
		
		if(waveStates.size() == 0)
			return null;
		return waveStates.get(0);
	}
	
	public void setPresentationState(String state)
	{
		this.presentationState = state;
	}
	
	public String getPresentationKey() 
	{
		return this.presentationKey;
	}
	
	public void setPresentationKey(String key)
	{
		this.presentationKey = key;
	}
	
	public String getNumberOfSlides() 
	{
		return this.numberOfSlides;
	}
	
	public void setNumberOfSlides(String num)
	{
		this.numberOfSlides = num;
	}
}
